//
//  BaseView.m
//  WhiteNoise
//
//  Created by 王亮 on 2020/8/11.
//  Copyright © 2020 liang. All rights reserved.
//

#import "TestView.h"

@interface TestView ()
@property(nonatomic,strong) UIButton *button;

@end
@implementation TestView
- (instancetype)initWithViewModel:(TestViewModel *)viewModel{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor redColor];
        [self bindViewModel:viewModel];
        
        [self addSubview:self.button];
        [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_offset(100);
            make.left.mas_offset(50);
            make.width.mas_offset(50);
            make.height.mas_offset(30);
        }];
        
    }
    return self;
}

-(void)bindViewModel:(TestViewModel *)viewModel{
    self.viewModel = viewModel;
    [self.viewModel.data_reload subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    [RACObserve(self.viewModel, dataArr) subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
}


-(RACSubject *)click_cell{
    if (_click_cell){
        _click_cell = [RACSubject subject];
    }
    return _click_cell;
}
-(UIButton *)button{
    if (!_button){
        _button = [[UIButton alloc]init];
        [_button setTitle:@"click" forState:UIControlStateNormal];
        
        [[_button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
            NSLog(@"%@",x);
        }];
    }
    return _button;
}

@end
